// Main.java
//
// Informatics 102 Spring 2012
// Code Example
//
// A quick example of our AccountOwnership aspect in action.

public class Main
{
	public static void main(String[] args)
	{
		Account account = new Account(1, 500);
		account.setOwnerName("Alex");

		Login.setCurrentUser("Alex");

		// We expect this withdrawl to succeed, because the current
		// user, "Alex," is also the owner of the account.
		try
		{
			account.withdraw(100);
			System.out.println(
				"Balance after first withdrawl: " + account.getBalance());
		}
		catch (InsufficientFundsException e)
		{
			System.out.println("First withdrawl failed: insufficient funds");
		}
		catch (AccountAccessException e)
		{
			System.out.println("First withdrawl failed: not owner");
		}
		
		Login.setCurrentUser("NotAlex");
		
		// We expect this withdrawl to fail, since the current user
		// is not the owner of the account.
		try
		{
			account.withdraw(400);
			System.out.println(
				"Balance after second withdrawl: " + account.getBalance());
		}
		catch (InsufficientFundsException e)
		{
			System.out.println("Second withdrawl failed: insufficient funds");
		}
		catch (AccountAccessException e)
		{
			System.out.println("Second withdrawl failed: not owner");
		}
	}
}
